﻿namespace OldMvcDemo.DALs;

public class AccountDAL
{
    private static List<AccountDALModel> _Accounts = new()
    {
        new(){ UserId = Guid.Parse("00000000-0000-0000-0000-000000000001"), AccountNo = "00001", Balance = 1000m },
        new(){ UserId = Guid.Parse("00000000-0000-0000-0000-000000000002"), AccountNo = "00002", Balance = 10m },
        new(){ UserId = Guid.Parse("00000000-0000-0000-0000-000000000003"), AccountNo = "00003", Balance = 200m },
        new(){ UserId = Guid.Parse("00000000-0000-0000-0000-000000000004"), AccountNo = "00004", Balance = 5m },
    };
    public async Task<AccountDALModel> GetAccountByIdAsync(Guid userId)
    {
        await Task.CompletedTask;
        return _Accounts.FirstOrDefault(r => r.UserId == userId);
    }

    public async Task<AccountDALModel> GetAccountByNoAsync(string no)
    {
        await Task.CompletedTask;
        return _Accounts.FirstOrDefault(r => r.AccountNo == no);
    }

    public async Task UpdateAsync(AccountDALModel account)
    {
        await Task.CompletedTask;
        var ac = _Accounts.FirstOrDefault(r => r.UserId == account.UserId);
        if (ac != null)
        {
            _Accounts.Remove(ac);
        }
        _Accounts.Add(account);
    }
}
